package com.heima.kafka.controller;

import com.alibaba.fastjson.JSON;
import com.heima.kafka.pojo.User;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class HelloController {
    @Resource
    private KafkaTemplate<String,String> kafkaTemplate;


    @GetMapping("/hello")
    public String hello(){
        User user = new User();
        user.setUsername("小米");
        user.setAge(19);
        kafkaTemplate.send("itcast-test","hello");
        kafkaTemplate.send("itcast-test", JSON.toJSONString(user));
        return "ok";
    }
}
